package com.subway.babynote;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import com.subway.babynote.syncdata.ClientDataRecord.contactRecord;
import com.subway.babynote.syncdata.ClientDataRecord.tipRecord;
import com.subway.babynote.syncservice.syncapi;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Button;

/*水*/
public class advice extends Activity {
	private static final int INVISIBLE = 0x00000004;
	String[] food_array;
	NotedbHelper notedb;
	ListView lv;
	Cursor cur;
	private LinearLayout linearLayout, statistics, sync, more;
	Intent In;
	Button login_button;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tips);
		setTitle(R.string.advice);
		notedb = new NotedbHelper(this);
		In = new Intent();
		lv = (ListView) findViewById(R.id.tips_list);
		login_button = (Button) findViewById(R.id.login_button);
		try {
			if (syncapi.getSyncImpl().getUserid() != -1) {
				login_button.setVisibility(INVISIBLE);
				login_button.setClickable(false);
			}
			/*
			 * cur= notedb.getTips(); ListAdapter listAdapter = new
			 * SimpleCursorAdapter(this, R.layout.advice_item, cur,new
			 * String[]{"content"}, new int[]{R.id.advice_item});
			 */
			List<tipRecord> lc = syncapi.getSyncImpl().getTips();
			ArrayList<HashMap<String, Object>> tips = new ArrayList<HashMap<String, Object>>();
			HashMap<String, Object> tip = new HashMap<String, Object>();
			Iterator<tipRecord> it = lc.iterator();
			while (it.hasNext()) {
				tip.put("content", it.next().content);
				tips.add(tip);
			}
			ListAdapter listAdapter = new SimpleAdapter(this, tips,
					R.layout.advice_item, new String[] { "content" },
					new int[] { R.id.advice_item });
			lv.setAdapter(listAdapter);
		} catch (Exception e) {
			Log.v("advice", " e=" + e.getMessage());
		}

		login_button.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				In.setClass(advice.this, login.class);
				startActivity(In);
			}
		});

	}

	public void onDestroy() {
		notedb.close();
		super.onDestroy();

	}

}